package com.user_service.controller;


import com.user_service.service.FollowService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follows")
@RequiredArgsConstructor
public class FollowController {
    private final FollowService followService;

    public ResponseEntity<String> followUser(@PathVariable Long followerId, @PathVariable Long followeeId){
        try{
            followService.followUser(followerId,followeeId);
            return ResponseEntity.ok("关注成功");
        }catch (RuntimeException  e){
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    @DeleteMapping("/{followeeId}")
    public ResponseEntity<String> unFollow(@PathVariable Long followerId, @PathVariable Long followeeId){
        try{
            followService.unFollow(followerId,followeeId);
            return ResponseEntity.ok("取消关注成功");
        }catch (RuntimeException  e){
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    @GetMapping("/followers/{userId}")
    public ResponseEntity<List<Long>> getFollowerIds(@PathVariable Long userId){
        List<Long> followerIds = followService.getFollowerIds(userId);
        return ResponseEntity.ok(followerIds);
    }

}
